package acidcart.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class FileUploadFactory {
	  
	  public static Widget StandardFileUpload() {
	    // Create a vertical panel to align the content
	    VerticalPanel vPanel = new VerticalPanel();

	    // Add a label
	    vPanel.add(new HTML("Select a file:"));

	    // Add a file upload widget
	    final FileUpload fileUpload = new FileUpload();
	    vPanel.add(fileUpload);

	    // Add a button to upload the file
	    Button uploadButton = new Button("Submit");
	    uploadButton.addClickHandler(new ClickHandler() {
	      public void onClick(ClickEvent event) {
	        String filename = fileUpload.getFilename();
	        if (filename.length() == 0) {
	          Window.alert("No File Found!");
	        } else {
	          Window.alert("File Uploaded!");
	        }
	      }
	    });
	    vPanel.add(uploadButton);

	    // Return the layout panel
	    return vPanel;
	  }
}
